package web_k;

import pojo_k.MainUser;
import service_k.HomeUserService;
import service_k.MainUserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/mainUserLoginServlet")
public class MainUserLoginServlet extends HttpServlet {
    private MainUserService service = new MainUserService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String mainuserName = request.getParameter("mainuserName");
        String mainuserPassword = request.getParameter("mainuserPassword");

        MainUser mainUser = service.mainUserSelect(mainuserName,mainuserPassword);

        //获取字符输出流，并设置content type
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();

        //3.判断user是否登陆成功
        if (mainUser != null){
            //登陆成功
            response.sendRedirect("/project1_war/MainUserPage.jsp");
        } else {
            //登陆失败
            writer.write("登陆失败");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
